<?php
	/**
	This file is part of PEL.
		PEL is free software: you can redistribute it and/or modify
		it under the terms of the GNU General Public License as published by
		the Free Software Foundation, either version 3 of the License, or
		(at your option) any later version.
		  
		PEL is distributed in the hope that it will be useful,
		but WITHOUT ANY WARRANTY; without even the implied warranty of
		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
		GNU General Public License for more details.
		  
		You should have received a copy of the GNU General Public License
		along with PEL.  If not, see <http://www.gnu.org/licenses/>.
	* Elgg pel edit/add page
	*/

// Set title, form destination
	if (isset($vars['entity'])){
		$action = "pel/edit";
		$native = $vars['entity']->description;
		$access_id = $vars['entity']->access_id;
	} 
	else{
		$action = "pel/add";
		$native = "";
		$access_id = 0;
	}

// Just in case we have some cached details
	if (isset($vars['pelnative'])){
		$native = $vars['pelnative'];
	}

  $title_label = elgg_echo('pel:native');
  $title_textbox = elgg_view('input/text', array('internalname' => 'pelnative', 'value' => $native));
  $access_label = elgg_echo('pel:acces');
  $access_input = elgg_view('input/access', array('internalname' => 'access_id', 'value' => $access_id));
  $submit_input = elgg_view('input/submit', array('internalname' => 'submit', 'value' => elgg_echo('Enregistrer')));

  if (isset($vars['entity'])){
    $entity_hidden = elgg_view('input/hidden', array('internalname' => 'guid', 'value' => $vars['entity']->getGUID()));
  } 
	else{
    $entity_hidden = '';
  }

  $form_body = <<<EOT
		<p>
			<label>$title_label</label><br />
      $title_textbox
		</p>
		<p>
			<label>$access_label</label><br />
      $access_input
		</p>
		<p>
			$entity_hidden
			$submit_input
		</p>
EOT;

  echo elgg_view('input/form', array(	'action' => "{$vars['url']}action/$action", 
																					'body' => $form_body,
																					'enctype' => "multipart/form-data"));
?>
